<?php

class usrprofilecontact_model extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->tableName = "usr_profile_contact";
    }
    
    function insert($mpa_id_alumni, $upc_category, $upc_contact_label, $upc_contact_value, $upc_ispublic) {
        $dt = array("mpa_id_alumni" => $mpa_id_alumni,
            "upc_category" => $upc_category,
            "upc_contact_label" => $upc_contact_label,
            "upc_contact_value" => $upc_contact_value,
            "upc_ispublic" => $upc_ispublic);
        $this->db->insert($this->tableName, $dt);
        return $this->db->insert_id();
    }
    
    function update($upc_id, $dt, $where = "") {
        $this->db->where("upc_id", $upc_id);
        if ($where != "")
            $this->db->where($where);
        $this->db->update($this->tableName, $dt);
    }

    function delete($upc_id, $where = "") {
        $this->db->where("upc_id", $upc_id);
        if ($where != "")
            $this->db->where($where);
        $this->db->delete($this->tableName);
    }

    function getById($upc_id, $where = "") {
        $this->db->where("upc_id", $upc_id);
        if ($where != "")
            $this->db->where($where);
        return $this->db->get($this->tableName)->row();
    }
    
    function getByUser($mpa_id_alumni, $where = "") {
        $this->db->where("mpa_id_alumni", $mpa_id_alumni);
        if ($where != "")
            $this->db->where($where);
        $this->db->order_by('upc_category', 'ASC');
        return $this->db->get($this->tableName)->result();
    }
    
    function getAll($startpage = "0", $perpage = "10", $where = "", $orderby = "") {
        if ($where != "")
            $this->db->where($where);
        $this->db->limit($perpage, $startpage);
        if ($orderby != "")
            $this->db->order_by($orderby);
        return $this->db->get($this->tableName)->result();
    }

    function getAllCount($where = "") {
        $this->db->select("COUNT(*) JUMLAH");
        $this->db->from($this->tableName);
        if ($where != "")
            $this->db->where($where);
        return $this->db->get()->row()->JUMLAH;
    }
}